package com.shxy.rlzy.mapper;

import com.shxy.rlzy.entity.Depart;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shxy.rlzy.entity.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author tanhao
 * @since 2021-09-23
 */
public interface DepartMapper extends BaseMapper<Depart> {

    /**
     * 查询全部部门信息
     * @return
     */
    @Select("select * from emp_depart")
    List<Depart> getAll();

    /**
     * 设置部门工资员
     * @param id
     * @param clerkId
     * @return
     */
    @Update("UPDATE emp_depart SET clerk_id=#{clerkId} WHERE id=#{id}")
    int setClerk(Long id, Long clerkId);

    /**
     * 获取部门工资员用户
     * @param departId
     * @return
     */
    @Select("SELECT su.* " +
            "FROM sys_user AS su " +
            "INNER JOIN sys_role AS sr " +
            "INNER JOIN sys_user_role AS sur " +
            "INNER JOIN emp_depart AS ed " +
            "INNER JOIN emp_info AS ei " +
            "ON sur.user_id=su.id " +
            "AND sur.role_id=sr.id " +
            "AND ed.clerk_id=ei.id " +
            "AND su.phone=ei.phone " +
            "WHERE sr.code='clerk' AND ed.id=#{departId}")
    User getDepartClerk(Long departId);
}
